'use strict'

class PlayerSessionMgr {
    constructor() {
        this.sessions = {} //保存pid对应的player
        this.sessionsUid = {} //保存uid对应的player
    }

    bind(player) {
        this.sessions[player.pId] = player
        this.sessionsUid[player.uId] = player
    }

    getPlayer(pId) {
        return this.sessions[pId]
    }

    getPlayerByUid(uId) {
        return this.sessionsUid[uId]
    }


    delPlayer(pId) {
        let player = this.sessions[pId]
        delete this.sessions[player.pId]
        delete this.sessionsUid[player.uId]
    }
}

let playerSessionMgr = new PlayerSessionMgr()
module.exports = playerSessionMgr
